package com.taotao.service.impl;

import com.taotao.common.pojo.TaotaoResult;
import com.taotao.mapper.TbItemParamMapper;
import com.taotao.pojo.TbItemParam;
import com.taotao.pojo.TbItemParamExample;
import com.taotao.service.ItemParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Package com.taotao.service.impl
 * @Description:
 * @Author elwyn
 * @Date 2017/9/3 17:50
 * @Email elonyong@163.com
 */
@Service
public class ItemParamSerivceImpl implements ItemParamService {
    @Autowired
    private TbItemParamMapper paramMapper;

    @Override
    public TaotaoResult getItemParamById(Long cid) {
        TbItemParamExample tbItemParamExample = new TbItemParamExample();
        TbItemParamExample.Criteria criteria = tbItemParamExample.createCriteria();
        criteria.andItemCatIdEqualTo(cid);
        List<TbItemParam> tbItemParams = paramMapper.selectByExampleWithBLOBs(tbItemParamExample);
        if (tbItemParams != null && !tbItemParams.isEmpty()) {
            return TaotaoResult.ok(tbItemParams.get(0));
        }
        return TaotaoResult.ok();
    }

    @Override
    public TaotaoResult insertItemParam(TbItemParam tbItemParam) {
        tbItemParam.setCreated(new Date());
        tbItemParam.setUpdated(new Date());
        paramMapper.insert(tbItemParam);
        return TaotaoResult.ok();
    }
}
